/**
 * 
 */
package org.apache.lucene.search;

import org.apache.lucene.index.FieldInvertState;

/**
 * 相似度评估器
 * 
 * 重载了DefaultSimilarity的coord,tf方法
 * 
 * @author Liuye
 * 
 */
@SuppressWarnings("serial")
public class B2BSimilarity extends DefaultSimilarity {

	/**
	 * 提高词元命中个数在相似度比较中的权重影响，即，当有多个词元得到匹配时，文档的相似度将提高
	 * 
	 * @see org.apache.lucene.search.DefaultSimilarity#coord(int, int)
	 */
	@Override
	public float coord(int overlap, int maxOverlap) {
		return 1f;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.apache.lucene.search.DefaultSimilarity#computeNorm(java.lang.String,
	 * org.apache.lucene.index.FieldInvertState)
	 */
	@Override
	public float computeNorm(String field, FieldInvertState state) {
		return 1f;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.lucene.search.DefaultSimilarity#idf(int, int)
	 */
	@Override
	public float idf(int docFreq, int numDocs) {
		return 1f;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.lucene.search.DefaultSimilarity#queryNorm(float)
	 */
	@Override
	public float queryNorm(float sumOfSquaredWeights) {
		return 1f;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.lucene.search.DefaultSimilarity#sloppyFreq(int)
	 */
	@Override
	public float sloppyFreq(int distance) {
		return 1f;
	}

	/**
	 * 降低项频率的权重影响，项频率>1的按1计算，防止关键字堆砌
	 * 
	 * 
	 * 项频率是指 项 t 在 文档 d 中出现的次数 frequency
	 * 
	 * @see org.apache.lucene.search.DefaultSimilarity#tf(float)
	 */
	@Override
	public float tf(float freq) {
		return 1f;
	}
}
